## Host system
HOST = linux-x86

## Android root directory
ANDROID_BASE = /opt/droid

ANDROID_NDK_BASE = /opt/android-ndk-r7b

## Android lib directory
ANDROID_LIBPATH = $(ANDROID_BASE)/lib


ANDROID_INCLUDES = \
	-I$(ANDROID_BASE)/dalvik/libnativehelper/include \
	-I$(ANDROID_BASE)/frameworks/base/include \
	-I$(ANDROID_BASE)/frameworks/base/include/media/stagefright/openmax \
	-I$(ANDROID_BASE)/frameworks/base/media/libstagefright/include \
	-I$(ANDROID_BASE)/hardware/libhardware/include \
	-I$(ANDROID_BASE)/system/core/include

ANDROID = android-9

# pthreads forced define for inline stuff from threads.h
CFLAGS_EXTRA += -Werror -Wall -Wno-multichar -DHAVE_PTHREADS -DLOG_MASK=0x0f -DENABLE_DEBUG 

ANDROID_TOOL_PREFIX = $(ANDROID_NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(HOST)/bin/arm-linux-androideabi-

ANDROID_CFLAGS = -msoft-float -fpic -mthumb-interwork \
	-funwind-tables -fstack-protector -fno-short-enums \
	-fno-exceptions -fno-rtti \
	-DANDROID -O0 -g -fno-omit-frame-pointer \
	$(CFLAGS_EXTRA) \
	-I$(ANDROID_NDK_BASE)/platforms/$(ANDROID)/arch-arm/usr/include/ \
	-I$(ANDROID_NDK_BASE)/sources/cxx-stl/gnu-libstdc++/include \
	-I$(ANDROID_NDK_BASE)/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include \
	$(ANDROID_INCLUDES) \
	-I/home/myshare/ffmpeginclude

# Android link flags 
ANDROID_LDFLAGS = -shared -nostdlib --no-undefined -Bsymbolic  -L$(ANDROID_LIBPATH) -lGLESv2 -lEGL


ANDROID_LIBS = -L$(ANDROID_NDK_BASE)/platforms/$(ANDROID)/arch-arm/usr/lib \
	-lc -lstdc++ -lm -llog \
	./libffmpeg.so ./libPPPP_API.a \
	$(ANDROID_NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(HOST)/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a \
	 -g -lutils -lnativehelper 

 
libobject_jni.so: object_jni.o SearchDVS.o CameraMediaSource.o CircleBuf.o VideoPlayer.o H264Decoder.o cgiwrapper.o httpwrapper.o global_h264decoder.o PPPPChannel.o PPPPChannelManagement.o Adpcm.o CgiPacket.o
	$(ANDROID_TOOL_PREFIX)ld $(ANDROID_LDFLAGS) -o libobject_jni.so object_jni.o SearchDVS.o CameraMediaSource.o CircleBuf.o VideoPlayer.o H264Decoder.o cgiwrapper.o httpwrapper.o global_h264decoder.o PPPPChannel.o PPPPChannelManagement.o Adpcm.o CgiPacket.o $(ANDROID_LIBS) 

#ANDROID_LIBS = -L$(ANDROID_NDK_BASE)/platforms/$(ANDROID)/arch-arm/usr/lib \
#	-lc -lstdc++ -lm -llog \
#	./libffmpeg.so ./libPPPP_API.so \
#	$(ANDROID_NDK_BASE)/toolchains/arm-linux-androideabi-4.4.3/prebuilt/$(HOST)/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a \
#	 -g -lutils -lnativehelper 

 
#libobject_jni.so: object_jni.o SearchDVS.o CameraMediaSource.o CircleBuf.o VideoPlayer.o H264Decoder.o cgiwrapper.o httpwrapper.o global_h264decoder.o PPPPChannel.o PPPPChannelManagement.o Adpcm.o CgiPacket.o
#	$(ANDROID_TOOL_PREFIX)ld $(ANDROID_LDFLAGS) -o libobject_jni.so object_jni.o SearchDVS.o CameraMediaSource.o CircleBuf.o VideoPlayer.o H264Decoder.o cgiwrapper.o httpwrapper.o global_h264decoder.o PPPPChannel.o PPPPChannelManagement.o Adpcm.o CgiPacket.o $(ANDROID_LIBS) 


object_jni.o: object_jni.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c object_jni.cpp -o object_jni.o
	
SearchDVS.o: SearchDVS.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c SearchDVS.cpp -o SearchDVS.o
	
CircleBuf.o: CircleBuf.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c CircleBuf.cpp -o CircleBuf.o
		
CameraMediaSource.o: CameraMediaSource.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c CameraMediaSource.cpp -o CameraMediaSource.o
	
VideoPlayer.o: VideoPlayer.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c VideoPlayer.cpp -o VideoPlayer.o
	
H264Decoder.o: H264Decoder.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c H264Decoder.cpp -o H264Decoder.o
	
cgiwrapper.o: cgiwrapper.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c cgiwrapper.cpp -o cgiwrapper.o
	
httpwrapper.o: httpwrapper.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c httpwrapper.cpp -o httpwrapper.o
	
#EGLDisplay.o: EGLDisplay.cpp 
#	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c EGLDisplay.cpp -o EGLDisplay.o
	
global_h264decoder.o: global_h264decoder.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c global_h264decoder.cpp -o global_h264decoder.o
	
PPPPChannel.o: PPPPChannel.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c PPPPChannel.cpp -o PPPPChannel.o
	
PPPPChannelManagement.o: PPPPChannelManagement.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c PPPPChannelManagement.cpp -o PPPPChannelManagement.o
	
Adpcm.o: Adpcm.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c Adpcm.cpp -o Adpcm.o
	
CgiPacket.o: CgiPacket.cpp 
	$(ANDROID_TOOL_PREFIX)g++ $(ANDROID_CFLAGS) -c CgiPacket.cpp -o CgiPacket.o


# Clean by deleting all the objs and the lib
clean:
	rm -fr *.o libobject_jni.so
